/**
 * @param {Object} string
 * @return	the first letter of the module (library or class) name
 */
getFirstLetter = function(string) {
	var index = string.lastIndexOf("/");

	if (index >= 0) {
		return string.charAt(index + 1);
	} else {
		return string.charAt(0);
	}
}

/**
 * @param {Object} string
 * @return true if the given string is a library path; false otherwise.
 */
isLibrary = function(string) {
	var c = getFirstLetter(string);
	
	if (c >= 'a' && c <= 'z') {
		return true;
	} else {
		return false;
	}
}

/**
 * @param {Object} string
 * @return	true if the string given is a class path; false otherwise.
 */
isClass = function(string) {
	var c = getFirstLetter(string);
	
	if (c >= 'A' && c <= 'Z') {
		return true;
	} else {
		return false;
	}
}

/*
 Naming conventions:
 * a class file always starts with majuscule and has the following extension: .class.js
 * a library file always starts with minuscle and has the following extension: .js
 * packages have the same meaning as in Java; "." means a new package inside the current one (a folder inside the current folder)

 example:
 considering LIBRARY_PATH="js/"
 package1.package2.Class1 will load js/package1/package2/Class1.class.js
*/

// make sure you have a slash at the end of your path
var LIBRARY_PATH = "js/";

/**
 * Import a module from an uri.
 * @param {Object} uri
 */
Import = function(uri) {
	uri = uri.replace(".", "/");

	if (isLibrary(uri)) {
		uri += ".js";
	} else if (isClass(uri)) {
		uri += ".class.js";
	} else {
		alert("Invalid import : " + uri);
	}

	uri = LIBRARY_PATH + uri;
	script = '<script src="' + uri +'" type="text/javascript"></script>\n';	
	
	document.write(script);
}

// Imports all necesary modules
Import("gg.Button");
Import("gg.ColorChooserButton");
Import("gg.StyleChooserButton");
Import("gg.Separator");
Import("gg.ButtonsFactory");
Import("gg.Editor");
Import("gg.Debug");
